package com.zhenhunfan.hello.rpc.demo01;

import com.zhenhunfan.hello.rpc.common.User;

import java.io.*;
import java.net.Socket;

/**
 * <p>Title: Client</p>
 * <p>Description: </p>
 *
 * @author zhenhunfan
 * @version 1.0.0
 * @date 2021/4/8
 */
public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost", 9000);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        dos.writeInt(123);

        OutputStream out = socket.getOutputStream();
        out.write(baos.toByteArray());
        out.flush();

        DataInputStream dis = new DataInputStream(socket.getInputStream());
        int i = dis.readInt();
        String name = dis.readUTF();
        User user = new User(i,name);

        System.out.println(user);
        dos.close();
        socket.close();
    }
}
